#Include <ScreenCapture.au3>
#Include <File.au3>
#Include <Function For Scan.au3>
#Include <GuiListView.au3>
Common_WriteCurrentFunctionNameToTempTXT($sScanFunctionName)
Global $sExcelSheetName = 'Scan Parameter-Non UI(WIA)', $iTotalTestCaseNumber = ''
If Assign('iTotalTestCaseNumber', TotalTestCaseNumber($sExcelSheetName)) And $iTotalTestCaseNumber == '' Then Exit
Common_DllCopy()
WIA_NONUI()
CloseOpenedExcel($oExcel)
Common_DllRemove()

Func WIA_NONUI()
	For $i = 1 to $iTotalTestCaseNumber
		Local $iRowInExcel = $i + 1, $TestCaseID = 'WIA_NONUI_' & $i, $sExtension = '', $sBrightness = '', $sContrast = '', $sContinueScan = '', $sAutoCrop = '' , $iDescreen = '', $iDPI = '', $sEnableDocuementFeederStstus = '', $sSaveAsType = '', $hPMHandle = '', $sColorMode= '',$sScansize = '', $hScanSettingDialog = '', $bReproduceTestCase = False, $sType = ''  
		If Assign('bReproduceTestCase', Common_ReproduceRunWithIni($sFindFunctionName,$TestCaseID)) And $bReproduceTestCase == False Then Return 3
		If Common_IsTestCaseLevelQualified(Common_GetTestCaseLevel($oExcel, $TestCaseID,$sExcelSheetName,$iCurrentSheetTotalLineNumber)) == False Then Return 2
		Common_Del_DB()
		Common_InitializeStatus()
		InitializeStatusForScan()
		If Assign('hPMHandle', Common_Run_PageManager_Ex($TestCaseID, $sScanFunctionName)) And $hPMHandle == '' Then ContinueLoop
		If Not Common_SwitchToFunctionFolder($hPMHandle, $sFolderName, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Not SelectDriverInSelectSource($sScannerDriverNameInSelectSourceWIA,$TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('hScanSettingDialog', OpenScanSettingsDialogFromFileMenu($TestCaseID, $sScanFunctionName)) And $hScanSettingDialog == '' Then ContinueLoop
		If Not NonUIScanCheckBoxInScanSettingDlg('Checkin', $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('sType', GetDocumentTypeFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sType == '' Then ContinueLoop
		If Not SetDocumentType($sType, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('sColorMode', GetColorModeFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sColorMode == '' Then ContinueLoop
		If Not SetColorMode($sColorMode, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		Local $validColorString = ImageTypeValidByDll($sColorMode)
		If Assign('sScansize', GetScanSizeFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sScansize == '' Then ContinueLoop	
		If Not SetScanSize($sScansize, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('iDPI', GetDPIFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $iDPI == '' Then ContinueLoop
		If Not SetDPI($iDPI, $TestCaseID, $sScanFunctionName, 'WIA') Then ContinueLoop
		Local $validDPIString = ImageDPIValidByDll($iDPI)
		If Assign('sSaveAsType', GetSaveAsTypeFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sSaveAsType == '' Then ContinueLoop
		If Not SetSaveAsType($sSaveAsType, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('sEnableDocuementFeederStstus', GetEnableDocumentFeederStatusFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sEnableDocuementFeederStstus == '' Then ContinueLoop
		If Not EnableDocumentFeederCheckBoxInScanSettingDlg($sEnableDocuementFeederStstus, $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('iDescreen', GetDecreenStatusFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $iDescreen == '' Then ContinueLoop	
		If Not EnableDDescreenCheckboxCheckBoxInScanSettingDlg($sEnableDocuementFeederStstus, $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('sAutoCrop', GetAutocropStatusFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sAutoCrop == '' Then ContinueLoop
		If Not AutoCroppingCheckboxCheckBox($sAutoCrop, $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('sContinueScan', GetContinueScanStatusFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sContinueScan == '' Then ContinueLoop
		If Not ContinueScanCheckBoxInScanSettingDlg($sContinueScan, $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Assign('sBrightness', GetBrightnessStatusFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sBrightness == '' Then ContinueLoop		
		If Assign('sContrast', GetContrastStatusFromExcel($sExcelSheetName, $iRowInExcel, $TestCaseID, $sScanFunctionName)) And $sContrast == '' Then ContinueLoop		
		If Not SetContrast($sColorMode, $sBrightness, $sContrast, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Not SetPrefixValueInScanSettingDlg($TestCaseID & '_', $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Not ClickButtonInScanSettingDlg('OK', $hScanSettingDialog, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Not ClickScanButtonInToolBar($hPMHandle, $ScanButtonInToolbar, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If Not WaitScanFinished_WIA($sScanningProgressBarDlgTitleWIA,180, $TestCaseID, $sScanFunctionName) Then ContinueLoop
		If $TestCaseID == 'WIA_NONUI_42' Then   ;CLose continue scan dlg
			Sleep(15000)
			WinActivate('[CLASS:#32770]', '&Yes')
			Sleep(300)
			ControlClick('[CLASS:#32770]', '&Yes', 'Button2')			
		EndIf
		If Assign('sExtension', FileExtension($sSaveAsType, $TestCaseID, $sScanFunctionName)) And $sExtension == '' Then ContinueLoop 
		Local $sScanedFile = $PMFolder & $TestCaseID & '_' & '0001' & $sExtension
		If IsScannedFileCreated($sScanedFile) Then
			FileCopy($sScanedFile, $sPerformResultPath, 1)
			Local $validWeightString, $validHightString
			If StringInStr($sScanedFile,'pdf') Then
				If FileExists($sScanedFile) Then
					Common_WriteLog($sPass, $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				Else
					Common_WriteLog($sFaile & 'No scanned file.', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				EndIf
			Else
				If $TestCaseID == 'WIA_NONUI_1' Or $TestCaseID == 'WIA_NONUI_6' Then
					$validWeightString = '360'
					$validHightString = '205'
				ElseIf $TestCaseID == 'WIA_NONUI_2' Then
					$validWeightString = '944'
					$validHightString = '820'
				ElseIf $TestCaseID == 'WIA_NONUI_3' Then
					$validWeightString = '9921'
					$validHightString = '14032'
				ElseIf $TestCaseID == 'WIA_NONUI_4' Then
					$validWeightString = '2112'
					$validHightString = '752'
				ElseIf $TestCaseID == 'WIA_NONUI_5' Or $TestCaseID == 'WIA_NONUI_11' Then
					$validWeightString = '632'
					$validHightString = '548'				
				ElseIf $TestCaseID == 'WIA_NONUI_7' Then
					$validWeightString = '908'
					$validHightString = '872'
				ElseIf $TestCaseID == 'WIA_NONUI_8' Then
					$validWeightString = '1888'
					$validHightString = '1640'
				ElseIf $TestCaseID == 'WIA_NONUI_9' Then
					$validWeightString = '1260'
					$validHightString = '1095'
				ElseIf $TestCaseID == 'WIA_NONUI_10' Then
					$validWeightString = '2112'
					$validHightString = '752'				
				ElseIf $TestCaseID == 'WIA_NONUI_11' Then
					$validWeightString = '300'
					$validHightString = '500'	
				ElseIf $TestCaseID == 'WIA_NONUI_13' Then
					$validWeightString = '496'
					$validHightString = '298'
				ElseIf $TestCaseID == 'WIA_NONUI_14' Then
					$validWeightString = '690'
					$validHightString = '446'
				ElseIf $TestCaseID == 'WIA_NONUI_15' Then
					$validWeightString = '1216'
					$validHightString = '504'
				ElseIf $TestCaseID == 'WIA_NONUI_16' Then
					$validWeightString = '202'
					$validHightString = '88'				
				ElseIf $TestCaseID == 'WIA_NONUI_17' Then
					$validWeightString = '430'
					$validHightString = '258'				
				ElseIf $TestCaseID == 'WIA_NONUI_18' Then
					$validWeightString = '730'
					$validHightString = '495'				
				ElseIf $TestCaseID == 'WIA_NONUI_19' Then
					$validWeightString = '4320'
					$validHightString = '1776'				
				ElseIf $TestCaseID == 'WIA_NONUI_20' Then
					$validWeightString = '1442'
					$validHightString = '592'	
				ElseIf $TestCaseID == 'WIA_NONUI_21' Then
					$validWeightString = '2160'
					$validHightString = '896'				
				ElseIf $TestCaseID == 'WIA_NONUI_22' Then
					$validWeightString = '705'
					$validHightString = '500'
				ElseIf $TestCaseID == 'WIA_NONUI_23' Then
					$validWeightString = '214'
					$validHightString = '102'
				ElseIf $TestCaseID == 'WIA_NONUI_24' Then
					$validWeightString = '4320'
					$validHightString = '1776'
				ElseIf $TestCaseID == 'WIA_NONUI_25' Then
					$validWeightString = '125'
					$validHightString = '161'										
				ElseIf $TestCaseID == 'WIA_NONUI_26' Then
				ElseIf $TestCaseID == 'WIA_NONUI_31' Then
					$validWeightString = '5100'
					$validHightString = '6599'						
				ElseIf $TestCaseID == 'WIA_NONUI_32' Then
					$validWeightString = '1700'
					$validHightString = '2200'
					$validDPIString = '96'					
				ElseIf $TestCaseID == 'WIA_NONUI_33' Then
					$validWeightString = '3307'
					$validHightString = '4677'
					$validDPIString = '96'					
					$validColorString = 'Color'
				ElseIf $TestCaseID == 'WIA_NONUI_34' Then
					$validWeightString = '4300'
					$validHightString = '6071'	
				ElseIf $TestCaseID == 'WIA_NONUI_35' Then
					$validWeightString = '2330'
					$validHightString = '3307'
					$validDPIString = '96'						
				ElseIf $TestCaseID == 'WIA_NONUI_36' Then
					$validWeightString = '300'
					$validHightString = '500'
				ElseIf $TestCaseID == 'WIA_NONUI_37' Then
					$validWeightString = '500'
					$validHightString = '300'					
				ElseIf $TestCaseID == 'WIA_NONUI_38' Then
					$validWeightString = '2400'
					$validHightString = '3600'
					$validDPIString = '96'						
				ElseIf $TestCaseID == 'WIA_NONUI_39' Then
					$validWeightString = '1800'
					$validHightString = '1200'					
				ElseIf $TestCaseID == 'WIA_NONUI_40' Then
					$validWeightString = '2000'
					$validHightString = '2800'
				ElseIf $TestCaseID == 'WIA_NONUI_41' Then
					$validWeightString = '1800'
					$validHightString = '3000'					
				ElseIf $TestCaseID == 'WIA_NONUI_42' Then
					$validWeightString = '1700'
					$validHightString = '2200'					
				EndIf
				Local $sRes = 0
				If $i >= 1 Or $i <= 28 Then
					$sRes = Common_ScanImageCompare_($sScanedFile,$validColorString,$validDPIString)
				Else
					$sRes = Common_ScanImageCompare($sScanedFile,$validColorString,$validDPIString,$validWeightString,$validHightString)
				EndIf
				If $sRes == 1 Then
					Common_WriteLog($sPass, $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				ElseIf $sRes == -1 Then
					Common_WriteLog($sFaile & 'The property of image color incorrect!', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
					Common_WriteLog(Common_GetImageType ($sScanedFile)& '        Clolor', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				ElseIf $sRes == -2 Then
					Common_WriteLog($sFaile & 'The property of image DPI incorrect!', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
					Common_WriteLog(Common_GetImageDPI ($sScanedFile)& '        DPI', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				ElseIf $sRes == -3 Then
					Common_WriteLog($sFaile & 'The property of image Size incorrect!', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
					Common_WriteLog(Common_GetImageHeight ($sScanedFile)& '        Height', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
					Common_WriteLog(Common_GetImageWidth ($sScanedFile)& '        Width', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				ElseIf $sRes == -4 Then
					Common_WriteLog($sFaile & 'The property of image Size incorrect!', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
					Common_WriteLog(Common_GetImageWidth ($sScanedFile)& '        Width', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
					Common_WriteLog(Common_GetImageHeight ($sScanedFile)& '        Height', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
				EndIf
			EndIf	
		Else
			Common_WriteLog($sFaile & 'No scanned file.', $TestCaseID, $sScanFunctionName, $bReproduceTestCase)
		EndIf
		Common_Close_PM($hPMHandle)
	Next
EndFunc
